package Sequence;

public class Test0714 {
}

class Solution0714 {
    public int maxProfit(int[] prices, int fee) {
        int length = prices.length;
        int[] dp = new int[2];

        dp[0] = -prices[0];
        for (int i = 1; i < length; i++) {
            int price = prices[i];
            int sale=Math.max(dp[0]+ price -fee, dp[1]);
            int buy = Math.max(sale-price, dp[0]);

            dp[0] = buy;
            dp[1] = sale;
        }

        return dp[1];
    }
}
